package com.dingli.admin.controller;

import com.dingli.admin.service.*;
import com.dingli.admin.service.impl.FindAllImpl;
import com.dingli.admin.service.impl.LoginUserImpl;
import com.dingli.framework.entity.User;
import com.dingli.framework.util.Response;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.List;

@CrossOrigin
@RestController
@RequestMapping("/user")
public class UserController {
    @Autowired
    private DeleteUser deleteUser;

    @Autowired
    private LoginUser loginUser;

    @Autowired
    private InsertUser insertUser;

    @Autowired
    private UpdateUser updateUser;

    @Autowired
    private FindAll findAll;

    @Autowired
    private FindOne findOne;

    @GetMapping("/login")
    public Response<User> login(@Param("name") String name, @Param("password") String password) {
        System.err.println("服务调用");
        return loginUser.getUser(name, password);
    }

    @GetMapping("/insert")
    public Response<User> insert(@Param("name") String name, @Param("password") String password) {
        return insertUser.insertUser(name, password);
    }

    @GetMapping ("/delete")
    public Response<User> delete(@Param("id") int user_id) {
        return deleteUser.deleteUser(user_id);
    }

    @GetMapping("/update")
    private Response<User> updateUser(User user){
        return updateUser.updateUser(user);
    }

    @GetMapping("/findAll")
    private Response<List<User>> findAll(){
        return findAll.findAll();
    }

    @GetMapping("/findOne")
    public Response<List<User>> findOne(@Param("id") int user_id){
        return findOne.findOne(user_id);
    }
}
